<?php
$config = [
    'host' => '127.0.0.1',
    'user' => 'root',
    'pass' => 'cxgphper',
    'db' => 'nuonuo',
];
$connect = @mysql_connect( $config['host'], $config['user'], $config['pass'] );
//var_dump($connect);
@mysql_query( "set names 'utf8'" );
@mysql_select_db( $config['db'] );
$sql = 'select user_id from tmp;';
$result = @mysql_query( $sql );
var_dump( "同步开始" );
while($row = @mysql_fetch_assoc( $result )) {
    //var_dump($row);
    $sql = "select decision_score,modelv21_response from system_user_report360 where user_id={$row['user_id']};";
    //var_dump($sql);
    $res = @mysql_query( $sql );
    $r = @mysql_fetch_assoc( $res );
    if($r !== false) {
        $response = json_decode( $r['modelv21_response'], true );
        $update = [
            'xigua_score' => $r['decision_score'] ? $r['decision_score'] : 'null',
            'count15days' => $response['ml-feature24'] ? $response['ml-feature24'] : 0,
            'count90days' => $response['ml-feature25'] ? $response['ml-feature25'] : 0,
            'count_call_halfyear' => $response['op-feature236'] ? $response['op-feature236'] : 0,
        ];
        $set = '';
        foreach($update as $key => $value) {
            $set .= ($key . '=' . $value . ',');
        }
        $set = rtrim( $set, ',' );
        $sql = "update tmp set {$set} where user_id={$row['user_id']};";
        $effect = @mysql_query( $sql );
        if(true === $effect) {
            var_dump( '成功更新一条' );
        }
    }
}
var_dump( "同步结束" );
